export default {
  //隔离不同模块名字
  namespaced: true,
  state: {
  /**
   * @description: 章节练习
   * */
  // 章节练习错题和类型
  chapTer:[], 
  //判断 在章节练习  哪题退出   
    chapTerState:{
      //开启询问  
      answering:false,  
      //最后一次跳转ID
      answeringId:null ,
      //退出时跳转索引
      answeringIndex:null,
    }, 
/**
   * @description: 模拟练习
   * */

   // 模拟真题错题和类型
   SimulatedRealTest:[],
   //查看解析状态  校验表单正确与否
   SimulatedRealState:false,
/**
* @description: 历年真题
* */ 

   //历年真题错题和类型
    previousExamPapers:[],
    //查看解析状态  校验表单正确与否
    SimulatedRealState:false,
    previousExamPapersState:false,

  //存倒计时  
    timeMsg: 0, 
    timeAll: 0,
    //存目前答题总时间
    timeAllCount:0,
    //存答题的使用时间
    timeUse:0,
  },
  mutations: {
   /**
   * @description: 章节练习
   * */
    //添加章节练习
    addcapter(state,item){                 
     state.chapTer.push(item)      
    }, 
     //章节练习题中途退出   开始询问上次退出时是哪一题    
   chapTerStateChage(state){
    state.chapTerState.answering=true      
   },
    //上次跳转ID 和index
   chapTerIdChage(state, payload){
      state.chapTerState.answeringId =payload.id
      state.chapTerState.answeringIndex =payload.index   
   },
     
   /**
   * @description: 模拟练习
   * */
    // 添加模拟真题 √
    addSimulatedRealTest(state,item){
      state.SimulatedRealTest.push(item)
    },
    //覆盖之前的 模拟题   
    mapSimulatedRealTest(state,payload){
        state.SimulatedRealTest= state.SimulatedRealTest.filter((item)=>{
            return  item.Cid!==payload.Cid
        }) 
        state.SimulatedRealTest.push(payload) 
    },
    //变成查看状态
    SimulatedRealTestToTrue(state){
        state.SimulatedRealState=true  
    },
/**
* @description: 历年真题
* */
    //添加历年真题
    addpreviousExamPapers(state,item){           
      state.previousExamPapers.push(item)         
    },
    //覆盖之前的  真题 √  
    mappreviousExamPapers(state,payload){
        state.previousExamPapers= state.previousExamPapers.filter((item)=>{
            return  item.Cid!==payload.Cid
   }) 
        state.previousExamPapers.push(payload) 
    },
    //   变成查看状态  
      previousExamPapersToTrue(state){
       state.previousExamPapersState=true
     },

  
    //时间  倒计时总值
      timeCal(state, val) {
      state.timeAll = val * 60
      console.log(state.timeAll);
    },
    //倒计时用的
      countTime (state) {
      if (state.timeAll >= 0) {
        var hours = Math.floor((state.timeAll / 3600) % 24) >= 1 ? Math.floor(state.timeAll / 3600) : '00'
        var minutes = Math.floor(state.timeAll / 60 % 60) < 10 ? '0' + Math.floor(state.timeAll / 60 % 60) : Math.floor(state.timeAll / 60 % 60);
        var seconds = Math.floor(state.timeAll % 60) < 10 ? '0' + Math.floor(state.timeAll % 60) : Math.floor(state.timeAll % 60);
        state.timeMsg = "距离答题结束还有 " + hours + '小时' + minutes + "分" + seconds + "秒";
        --state.timeAll;
      } else {
        console.log("答题结束")
      }
    }
  },
  getters:{
  },
  actions: {
    //倒计时
    countTimeAction ({ commit }, payload) {
      commit('timeCal', payload)
      setInterval(() => {
        commit('countTime')
      }, 1000);
    }
  }

}